<?php


namespace App\HttpController;


use App\Common\lib\Code;
use App\Exception\ApiException;
use App\Logic\UserLogic;
use EasySwoole\EasySwoole\Logger;
use EasySwoole\Http\AbstractInterface\Controller;

class User extends Controller
{
    /**
     * 微信登录
     * @return bool
     */
    public function login()
    {
        try {
            return $this->writeJson(Code::$success,(new UserLogic())->login($this->request()->getRequestParam()),'ok');
        }catch (\Exception $exception){
            if ($exception instanceof ApiException){
                return $this->writeJson($exception->getCode(),null,$exception->getMessage());
            }else{
                Logger::getInstance()->error($exception->getMessage());
            }
        }
    }
}